import 'package:flutter/material.dart';

class AnimatedAppear extends StatelessWidget {
  const AnimatedAppear({
    super.key,
    required this.child,
    this.delayMs = 0,
    this.durationMs = 300,
    this.offsetY = 12,
    this.beginOpacity = 0.0,
  });

  final Widget child;
  final int delayMs;
  final int durationMs;
  final double offsetY;
  final double beginOpacity;

  @override
  Widget build(BuildContext context) {
    return TweenAnimationBuilder<double>(
      tween: Tween(begin: 0, end: 1),
      duration: Duration(milliseconds: durationMs),
      curve: Curves.easeOutCubic,
      builder: (context, value, _) {
        return Opacity(
          opacity: beginOpacity + (1 - beginOpacity) * value,
          child: Transform.translate(
            offset: Offset(0, (1 - value) * offsetY),
            child: child,
          ),
        );
      },
    )
    // 使用 FutureBuilder 实现延时开始动画
    ;
  }
}
